*12-09-23_looprobustness.do


*Running single imputation robustness code in a loop


clear
macro drop _all
global filetree /Users/Allan/Dropbox/!!Papers/Liberal Peace/12-02-21_ISQ_commentary/DOR_ISQ_2013_Replication/M_Rep

cd "$filetree"

set more off

use "MM_precise.dta", clear

sort ccode1 ccode2 year
gen specification="NA"
gen specnumber=.
gen n=.
gen DmlCoefficient=.
gen DmlSE=.
gen CIElCoefficient=.
gen CIElSE=.

gen Dmlpvalues=.
gen CIElpvalues=.


sort ccode1 ccode2 year
global controls lncprt mjpw cntg dist numstate 

global fmcontrols lncprt mjpw cntg dist numstate fpceyrs fspl1 fspl2 fspl3

global amcontrols lncprt mjpw cntg dist numstate apceyrs aspl1 aspl2 aspl3

local j=0

**M2 with 4 misspecified dependent variables
local j=`j'+1
local spec`j' "(Mousseau 2013) Base Model"
local covars`j' "mzfmidl  CIEl  dml $fmcontrols"


local j=`j'+1
local spec`j' "M13 MID Onset"
local covars`j' "mzamidl CIEl  dml 	 $amcontrols"


local j=`j'+1
local spec`j' "M13 FMID Ongoing"
local covars`j' "mzfmidongl CIEl  dml 					   $fmcontrols"


local j=`j'+1
local spec`j' "M13 MID Ongoing"
local covars`j' "mzongol CIEl  dml 					   $controls midyears*"




**M2 with 4 dependent variables x interaction = 8 models
local j=`j'+1
local spec`j' ""
local covars`j' "mzmidonl CIEl  dml 					   $controls midyears*"


local j=`j'+1
local spec`j' "O"
local covars`j' "mzmidol CIEl  dml 					   $controls midyears*"


local j=`j'+1
local spec`j' "F"
local covars`j' "mzfmidonl CIEl  dml 					   $controls fatalyears*"


local j=`j'+1
local spec`j' "FO"
local covars`j'  "mzfmidol CIEl  dml 					   $controls fatalyears*"


local j=`j'+1
local spec`j'  "I"
local covars`j'  "mzmidonl CIElc  dml dmlCIElc 					   $controls midyears*"


local j=`j'+1
local spec`j'  "OI"
local covars`j'  "mzmidol CIElc  dml 	 dmlCIElc 				   $controls midyears*"


local j=`j'+1
local spec`j'  "FI"
local covars`j'  "mzfmidonl CIElc  dml 		 dmlCIElc 			   $controls fatalyears*"


local j=`j'+1
local spec`j'  "FOI"
local covars`j' "mzfmidol CIElc  dml  	dmlCIElc 				   $controls fatalyears*"



**M2 with DemocracyHigh, with 4 dependent variables x interaction = 8 models
local j=`j'+1
local spec`j' "D"
local covars`j' "mzmidonl CIEl  dml  dmh 					   $controls midyears*"

 
local j=`j'+1
local spec`j'  "OD"
local covars`j'  "mzmidol CIEl  dml  dmh 					   $controls midyears*"


local j=`j'+1
local spec`j'  "FD"
local covars`j'  "mzfmidonl CIEl  dml  dmh					   $controls fatalyears*"

local j=`j'+1
local spec`j'  "FOD"
local covars`j'  "mzfmidol CIEl  dml  dmh					   $controls fatalyears*"


local j=`j'+1
local spec`j'  "ID"
local covars`j'  "mzmidonl CIElc  dml dmlCIElc 	 dmh 				   $controls midyears*"


local j=`j'+1
local spec`j'  "OID"
local covars`j'  "mzmidol CIElc  dml 	 dmlCIElc 	 dmh 			   $controls midyears*"


local j=`j'+1
local spec`j'  "FID"
local covars`j'  "mzfmidonl CIElc  dml 		 dmlCIElc 	 dmh 		   $controls fatalyears*"


local j=`j'+1
local spec`j'  "FOID"
local covars`j'  "mzfmidol CIElc  dml  	dmlCIElc 	 dmh 			   $controls fatalyears*"




**Estimating Models, Saving Values
forvalues k=1(1)`j' {
logit `covars`k'', cl(ID) nolog
replace n= e(N)   if _n==`k'
replace specification="`spec`k''" if _n==`k'
replace specnumber=`k' if _n==`k'
replace DmlCoefficient=_b[dml] if _n==`k'
replace DmlSE=_se[dml] if _n==`k'
replace CIElCoefficient=_b[CIEl] if _n==`k'
replace CIElSE=_se[CIEl] if _n==`k'
}
 

replace Dmlpvalues=2*normal(-abs(DmlCoefficient/DmlSE))
replace CIElpvalues=2*normal(-abs(CIElCoefficient/CIElSE))
keep specification-CIElpvalues
drop if specnumber==.
saveold "robustness1.dta", replace





**Analyses with no ln(life insurance) or GDP

clear
macro drop _all
global filetree /Users/Allan/Dropbox/!!Papers/Liberal Peace/12-02-21_ISQ_commentary/DOR_ISQ_2013_Replication/M_Rep

cd "$filetree"

set more off

use "MM_precise.dta", clear

sort ccode1 ccode2 year
gen specification="NA"
gen specnumber=.
gen n=.
gen DmlCoefficient=.
gen DmlSE=.
gen CIElCoefficient=.
gen CIElSE=.

gen Dmlpvalues=.
gen CIElpvalues=.

sort ccode1 ccode2 year
global controls lncprt mjpw cntg dist numstate 

global fmcontrols lncprt mjpw cntg dist numstate fpceyrs fspl1 fspl2 fspl3

global amcontrols lncprt mjpw cntg dist numstate apceyrs aspl1 aspl2 aspl3

local j=0

**M1 with 4 dependent variables x DemocracyHigh = 8 models
local j=`j'+1
local spec`j' "n"
local covars`j' "mzmidonl   dml 					   $controls midyears*"

local j=`j'+1
local spec`j' "On"
local covars`j' "mzmidol   dml 					   $controls midyears*"

local j=`j'+1
local spec`j' "Fn"
local covars`j' "mzfmidonl   dml 					   $controls fatalyears*"

local j=`j'+1
local spec`j' "FOn"
local covars`j' "mzfmidol   dml 					   $controls fatalyears*"


local j=`j'+1
local spec`j' "Dn"
local covars`j' "mzmidonl   dml  dmh 					   $controls midyears*"

local j=`j'+1
local spec`j' "ODn"
local covars`j' "mzmidol   dml  dmh 					   $controls midyears*"

local j=`j'+1
local spec`j' "FDn"
local covars`j' "mzfmidonl   dml  dmh 					   $controls fatalyears*"

local j=`j'+1
local spec`j' "FODn"
local covars`j' "mzfmidol   dml  dmh					   $controls fatalyears*"



**Estimating Models, Saving Values
forvalues k=1(1)`j' {
logit `covars`k'', cl(ID) nolog
replace n= e(N)   if _n==`k'
replace specification="`spec`k''" if _n==`k'
replace specnumber=`k' if _n==`k'
replace DmlCoefficient=_b[dml] if _n==`k'
replace DmlSE=_se[dml] if _n==`k'
*replace CIElCoefficient=_b[CIEl] if _n==`k'
*replace CIElSE=_se[CIEl] if _n==`k'
}
 
replace Dmlpvalues=2*normal(-abs(DmlCoefficient/DmlSE))
replace CIElpvalues=2*normal(-abs(CIElCoefficient/CIElSE))
keep specification-CIElpvalues
drop if specnumber==.
saveold "robustness3.dta", replace

